package com.handu.luna.core.domain.article;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.handu.luna.core.domain.BaseRepository;



public interface ArticleListRepository extends JpaRepository<ArticleList,Long>, BaseRepository<ArticleList>,JpaSpecificationExecutor<ArticleList>{
 
	@Query("from ArticleList a")   //order by a.catId desc
	Page<ArticleList> findAll(Pageable pageable);
	
	/**
	 * 点击文章分类，列出相对应的文章列表
	 * @param id
	 * @param pageable
	 * @return
	 */
	@Query("from ArticleList a where a.catId=:id")
	Page<ArticleList> findAll(@Param("id") Long id,Pageable pageable);
	
	/**
	 * 当删除文章分类的时候，判断该分类下是否有文章，若有，则不允许删除
	 * @param id
	 * @return
	 */
	@Query("from ArticleList a where a.catId=:id")
	List<ArticleList> findAll(@Param("id") Long id);
	/**
	 * 更新文章的显示与 隐藏
	 */
	@Modifying
	@Query("update ArticleList a set a.displayed=:displayed where a.id=:id")
	void updateDisplayedTrue(@Param("displayed") Boolean displayed,@Param("id") Long id);
	
	/**
	 * 转移分类
	 */
	@Modifying
	@Query("update ArticleList a set a.catId = :catId where a.id=:id")
	void updateCategoryId(@Param("catId") Long catId,@Param("id") Long id);
	
	
	
}
